package core.controller.cmds;

import java.util.ArrayList;

import core.controller.CommandController;
import core.dal.AdminFunctionality;
import core.dto.IOperatorDTO;
import exceptions.UserNotFoundException;

public class ShowAllUsersCMD implements ICmd {

	AdminFunctionality functionality;
	final String level = "Admin";
	ICmd nextCMD;

	CommandController cc;

	public ShowAllUsersCMD(CommandController commandController,
			AdminFunctionality aF) {
		this.cc = commandController;
		functionality = aF;
	}

	@Override
	public void setNextCmd(ICmd nextCmd) {
		nextCMD = nextCmd;

	}

	@Override
	public void execute(String cmd) {
		if (cmd.equals("showAllUsers")) {
			cc.getTUI().showOutput("oprID -- oprName -- cpr -- pass ");
			cc.getTUI().showOutput("---------------------------------------");
			ArrayList<IOperatorDTO> userList = functionality.showUsers();
			for (int i = userList.size(); i > 0; i--) {
				cc.getTUI().showOutput(
						String.valueOf(userList.get(i - 1).getOprId()) + " -- "
								+ userList.get(i - 1).getOprNavn() + " -- "
								+ userList.get(i - 1).getCpr() + " -- "
								+ userList.get(i - 1).getPassword());
			}

		}

		if (nextCMD != null) {
			nextCMD.execute(cmd);
		}
	}

	@Override
	public String getInfo() {
		return "showAllUsers - Shows all users in the database";

	}

	@Override
	public String getLevel() {
		return this.level;

	}
}
